export class EventBus {
  events: Obj<Fn[]> = {};
  on = (event: string, handler: Fn) => {
    this.events[event] ||= [];
    this.events[event].push(handler);
  };
  emit = (event: string, data: any) => {
    this.events[event]?.forEach((handler) => {
      handler(data);
    });
  };
  off: (event: string, handler: Fn) => void = (event, handler) => {
    if (handler) this.events[event] = this.events[event].filter((h) => h !== handler);
    else delete this.events[event];
  };
}
